﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace WindowsFormsApplication1
{
    public partial class frmTKGVtheochucdanh : Form
    {
        SqlConnection connection = new SqlConnection("Data Source = .; Initial Catalog = SM; Integrated Security = True");
        public frmTKGVtheochucdanh()
        {
            InitializeComponent();
        }

        DataSet FillDataset(string sql)
        {
            DataSet ds = new DataSet();
            try
            {
                SqlDataAdapter adap = new SqlDataAdapter(sql, connection);
                adap.Fill(ds);
                adap.Dispose();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error " + ex.Message);
            }
            return ds;
        }

        private void btnChon_Click(object sender, EventArgs e)
        {
            bool ktra = dxValidationProvider1.Validate();
            if (ktra)
            {
                DataSet ds = FillDataset("exec PC_TKGVTheoChucDanh '" + dTungay.Text + "','" + dDenngay.Text + "'");
                int count = ds.Tables[0].Rows.Count;
                if (count == 0)
                {
                    MessageBox.Show("Không tìm thấy dữ liệu", "Thông báo");
                }
                else
                {
                    rptTKGVTheoChucDanh rpt = new rptTKGVTheoChucDanh();
                    rpt.DataSource = ds;
                    rpt.BindData(dTungay.Text, dDenngay.Text);
                    rpt.PrintingSystem.PreviewFormEx.MdiParent = RibbonForm1.ActiveForm;
                    rpt.ShowPreview();
                }
            }
            else
                MessageBox.Show("Bạn chưa nhập dữ liệu cần thiết", "Quản lý sinh viên", MessageBoxButtons.OK, MessageBoxIcon.None);
       
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
